<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
	<link rel="stylesheet" type="text/css" href="js/jquery-easyui-1.5/themes/default/easyui.css"></link>
	<link rel="stylesheet" type="text/css" href="js/jquery-easyui-1.5/themes/icon.css"></link>
	<link rel="stylesheet" type="text/css" href="js/jquery-easyui-1.5/demo/demo.css"></link>
	<script language="JavaScript"  type="text/javascript" src="js/jquery-easyui-1.5/jquery.min.js"></script>
	<script language="JavaScript"  type="text/javascript" src="js/jquery-easyui-1.5/jquery.easyui.min.js"></script>
	
	<script type="text/javascript">
	 /*<![CDATA[*/ 
	            
	            
	 var fsum;
	            
	  function clickQuery()
	 {
		 var tmp = encodeURIComponent($('#foodname').val());
		  var name = $.trim(tmp);  
		  if(name.length==0)
			  return;
		  var url = "getFoodByLike?foodname="+name;
		  $.get(url, function(data){
			  	$("#aa").datagrid("loadData", data);
				
				$("#count").html(data.length);
			});
	 }
	
		function showchar()
		 {
	         var deskid=$("#deskid").val();
	         var url ="showCar?deskid="+deskid;
			 $.get(url, function(data){
				if(data.total!="0")
				{
					//$("#table").datagrid({showFooter: true});
					var foot = data.footer;
					fsum = foot[0].price;
					
					$("#table").datagrid("loadData", data);
				}else
				{
					//$("#table").datagrid({showFooter: false});
					var json = $.parseJSON("{\"total\":0,\"rows\":[],\"footer\":[]}");
					$("#table").datagrid("loadData", json);
				}
				
			 });
		 }
	 
	 function removeCar(id)
	 {
		 var orderid = $("#orderid").val();
		 var url = "del_order?id="+id+"&orderid="+orderid;
		  
		  $.get(url, function(data){
			  showchar();
		  });
	 }
	 
	 function overCar(id)
	 {
		 var deskid = $("#deskid").val();
		 var desknum = $("#desknum").val();
		 var url = "over_order?id="+id+"&deskid="+deskid+"&sum="+fsum;
		  
		  $.get(url, function(data){
			  
			  showchar();
			  
			  var p = self.parent;
			  p.parent.closetab(desknum+"号桌");
			  p.parent.closetab(desknum+"号桌_有未读消息");
			  
		  });
	 }
	 
	 
	
	$(document).ready(  
			  function(){
				
				  $('#dlg').dialog('close');
				  $('#dlgev').dialog('close');
				  
				  $('#foodname').textbox('textbox').blur(function (){
					  $("#foodname").textbox("setValue", "");
				  });
				  
				  
				  $('#foodname').textbox('textbox').keydown(function (e) {
					  clickQuery();
				  });
				  
				  $('#dlg').tooltip({
						position: 'bottom',
						content: '<span style="color:#fff">双击菜单添加至购物车</span>',
						onShow: function(){
							$(this).tooltip('tip').css({
								backgroundColor: '#666',
								borderColor: '#666'
							});
						}
					});
				  
				  
				  showchar();
				  
				  
			  });
	
	 function formatColumn(val,row){
		 if(row.id=='sum')
			 {
			 	return '<input type="button" value="结算" onclick="overCar(\''+val+'\')" />';
			 }else
			 {
				 if(row.score=="0")
				 	return '<a href="#"  onclick="removeCar(\''+val+'\')">撤单</a>';
				 else
					 return '<a href="#"  onclick="getEvaluate(\''+row.orderid+'\',\''+row.foodname+'\')">查看评价</a>&nbsp;&nbsp;<a href="#"  onclick="removeCar(\''+val+'\')">撤单</a>';
			 }
			
		
	}
	 
	 function opendlg()
	 {
		 $('#dlg').dialog('open');
		 $('#foodname').textbox('textbox').focus(); 
	 }
	 
	 var flag=0;
	
	 function cellclick(index, field){
         if(field=='score')
         {
       		$('#aa')
 				.datagrid('beginEdit', index);
       		flag=1;
         }else
         {
        	 $('#aa')
				.datagrid('endEdit', index);
         }
    }
	 
	 function afterEdit(rowIndex,rowdata,changes)
	 	{
		    
		    var deskid = $("#deskid").val();
			 var url = "add_order?foodid="+rowdata.id+"&deskid="+deskid+"&count="+rowdata.score+"&flag=1";
			  $.ajax(
			 			{
			 	        	url: url,
			 	        	async: false,//改为同步方式
			 	        	type: "GET",
			 	        	success: function (data) {
			 	        		 flag=0;
			 	        		 showchar();
			 	 			}
			 	 	});
	    	
	 	}
	 
	 
	 function onClickRow(index,rowdata)
	 {
			 var deskid = $("#deskid").val();
			 var url = "add_order?foodid="+rowdata.id+"&deskid="+deskid+"&count="+rowdata.score+"&flag=1";
			  $.ajax(
			 			{
			 	        	url: url,
			 	        	async: false,//改为同步方式
			 	        	type: "GET",
			 	        	success: function (data) {
			 	        		 showchar();
			 	 			}
			 	 	});
		 
		 
	 }
	 
	 function close()
	 {
		 var json = $.parseJSON("[]");
		 $("#aa").datagrid("loadData", json);
	 }
	 
	 function getEvaluate(orgid,name)
	 {
		 $('#dlgev').panel({title: name});
		 
		 var url ="getEvaluate?orgid="+orgid;
		 
		 $.get(url, function(data){
			 
			 $("#icon").empty();

			if(typeof(data.score)=="undefined")
			{
				return;
			}else
			{
				var exp="input[name='ev'][value="+data.score+"]";
				$(exp).attr("checked",true);
				var html="";
				var len=parseInt(data.score);
				for(i=0;i<=len;i++)
				{
					html=html+'<img width="40px" height="40px" src="/myres/icon/nice.jpg"/>';
				}
				len=5-len-1;
				for(i=0;i<len;i++)
				{
					html=html+'<img width="40px" height="40px" src="/myres/icon/bad.jpg"/>';
				}
				$("#icon").append(html); 
				
			    $("#remark").val(data.remark);
			    
			    $('#dlgev').dialog('open');
			}
        	 
         });
	 }
	 
	    
	 	
	 	/*]]>*/  
	</script>
	
	
</head>
<body>

<div style="position:absolute;left:0px;top:0px" id="pp1">
<table id="table" class="easyui-datagrid" title="订单列表" style="width:400px;height:400px;"
			data-options="singleSelect:true,collapsible:false,showFooter: true,rownumbers: true,toolbar:'#tb'">
		<thead>
			<tr>
				<th data-options="field:'foodname'" width="30%">菜名</th>
				<th data-options="field:'price',editor:'text'" width="20%">价格</th>
				<th data-options="field:'count',editor:'text'" width="10%">数量</th>
				<th data-options="field:'orderid',align:'right',formatter:formatColumn" width="40%">操作</th>

			</tr>
		</thead>
	</table>
	</div>
	<input  id="deskid" type="hidden" th:value="${deskid}" />
	<input  id="orderid" type="hidden" th:value="${orderid}" />
	<input  id="desknum" type="hidden" th:value="${desknum}" />
	
	<div id="tb" style="padding:2px 5px;">
		<a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="opendlg()">新增菜单</a>
	</div>
	
	<div id="dlg" class="easyui-dialog" title="新增菜单" data-options="iconCls:'icon-save',modal:true,onClose:close" style="width:310px;height:320px;">
		<table id="aa" class="easyui-datagrid"  style="width:290px;height:280px;" 
			data-options="singleSelect:true,collapsible:false,onDblClickRow: onClickRow,onClickCell:cellclick,rownumbers: true,toolbar:'#tt'">
			<thead>
				<tr>
					<th data-options="field:'foodname'" width="40%">菜名</th>
					<th data-options="field:'price'" width="40%">价格</th>
					<th data-options="field:'score',align:'left',editor:{type:'numberspinner',options:{min:1}}" width="20%">数量</th>

				</tr>
			</thead>
		</table>
	</div>
	
	<div id="dlgev" class="easyui-dialog" title="客户评价" data-options="iconCls:'icon-info',modal:true,onClose:close" style="width:310px;height:190px;">
		<table width="100%">
          	 		<tr><td align="center" >
          	 			极差<input type="radio" name="ev" value="0" />&nbsp;&nbsp;&nbsp;
          	 			差<input type="radio" name="ev" value="1" />&nbsp;&nbsp;&nbsp;
          	 			一般<input type="radio" name="ev" value="2" />&nbsp;&nbsp;&nbsp;
          	 			好<input type="radio" name="ev" value="3" />&nbsp;&nbsp;&nbsp;
          	 			非常好<input type="radio" name="ev" value="4" />&nbsp;&nbsp;&nbsp;
          	 			
          	 			</td></tr>
          	 		</table>
          	 		
          	 		<div>
						<textarea class="comments" id="remark" cols="32"   placeholder="味道如何评价一下吧！" rows="4"></textarea>
					</div>
					<div id="icon"></div>
	</div>
	
	<div id="tt" style="padding:2px 5px;">
		
		<input class="easyui-textbox" data-options="prompt:'输入查询'" name ="foodname"  id="foodname" style="width:100px"/>
		<span id="count"></span>
		
	</div>
	
</body>
</html>